#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n, r;
  cin >> n >> r;
  // 10
  // 123    n%r   3 n/r = 12
  vector<int> digits;
  while (n) {
    digits.push_back(n % r);
    n /= r;
  }
  // 3 2 1
  reverse(digits.begin(), digits.end());
  // reverse(arr, arr + n);
  for (auto& d: digits) {
    if (d < 10) cout << d;
    else cout << char('A' + (d - 10));
  }
  cout << endl;
}